package com.zzhou.linkinfo.clock.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zzhou.linkinfo.clock.R;
import com.zzhou.linkinfo.clock.entity.TaskBean;

import java.util.ArrayList;
import java.util.List;

/**
 * <desc>
 * Created by The Moss on 2019/3/14.
 */

public class ClockMainAdapter extends BaseAdapter<ClockMainAdapter.ViewHolder> {
    List<TaskBean> mDatas;
    OnClickClockMainListener mListener;

    public interface OnClickClockMainListener{
        void onClickItemView(int position);
        void onClickEntance(int position);
    }

    public ClockMainAdapter(Context mContext) {
        super(mContext);
        mDatas = new ArrayList<>();
    }

    @NonNull
    @Override
    public ClockMainAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.clock_item_main,parent,false));
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public void setDatas(boolean isMore, List<TaskBean> mDatas){
        if (!isMore) {
            this.mDatas.clear();
        }
        if (mDatas != null) {
            this.mDatas.addAll(mDatas);
        }
        notifyDataSetChanged();
    }
    public void setClockListener(OnClickClockMainListener listener){
        if (listener != null) {
            this.mListener = listener;
        }
    }
    public class ViewHolder extends BaseAdapter.BaseViewHolder{

        private TextView titleTv;
        private TextView contentTv;
        private TextView audioTv;
        private TextView audioMisTv;
        private RecyclerView recyclerView;
        private TextView timeTv;
        private TextView entanceTv;
        public ViewHolder(View itemView) {
            super(itemView);
            titleTv = itemView.findViewById(R.id.item_clock_main_titleTv);
            contentTv = itemView.findViewById(R.id.item_clock_main_contentTv);
            audioTv = itemView.findViewById(R.id.item_clock_main_audioTv);
            audioMisTv = itemView.findViewById(R.id.item_clock_main_audioMisTv);
            recyclerView = itemView.findViewById(R.id.item_clock_main_recycleview);
            timeTv = itemView.findViewById(R.id.item_clock_main_dateTv);
            entanceTv = itemView.findViewById(R.id.item_clock_main_entanceTv);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener!=null){
                        mListener.onClickItemView(getAdapterPosition());
                    }
                }
            });
        }

        @Override
        public void setData(int position) {
            if (mListener!=null){
                mListener.onClickEntance(position);
            }
        }
    }
}
